﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<nsadv.Statistic.Web.ViewModels.StatisticDetailsModel>" %>


<%
	Func<int, int, string> GetCTR = delegate(int clicks, int shows)
										{
											if (clicks == 0)
												return 0.ToString("P");
											if (shows == 0)
												return "";
											return ((double)clicks / (double)shows).ToString("P");
										};
%>

<table class="bannerstbl" cellpadding="0" cellspacing="0">
	<thead><tr><td width="50">№</td><td>Баннер</td><td>Размещение</td><td>Показы / Расхлопы / Клики / CTR</td></tr></thead>
	<tbody>
		<% 
			int index = 0;		  	
			int showTotal = 0;
			int expandTotal = 0;	
			int clickTotal = 0;	
			foreach (var row in Model.BannerRows)
{
	index++;
	showTotal += row.Shows;
	expandTotal += row.Expands;
	clickTotal += row.Clicks;
				%>
		<tr>  
			<td><%: index%></td>
			<td>
			<% var bannerName = string.Format("{0}{1} ({2})", row.Banner.Name, row.Banner.IsTest ? " - тестовый" : "", row.Banner.Id); %> 
			<%: Html.ActionLink(bannerName, "BannerPeriodical", new RouteValueDictionary { {"id", row.Banner.Id}, {"platformId", Model.PlatformId}, {"placeId", Model.PlaceId} })%>
			</td>
			<td>
				<%= string.Format("{0} - {1}", 
					row.Banner.Campaign.StartTime.HasValue ? row.Banner.Campaign.StartTime.Value.ToShortDateString() : "<i>нет даты</i>",
					row.Banner.Campaign.EndTime.HasValue ? row.Banner.Campaign.EndTime.Value.ToShortDateString() : "<i>нет даты</i>"
				) %>
			</td>
			<td>
				<%: row.Shows %> / 
				<%: row.Expands %> / 
				<%: row.Clicks %> / 
				<span class="red"><%: GetCTR(row.Clicks, row.Shows) %></span></td>
		</tr>
<% } %>

	</tbody>
	<tfoot>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td><span class="bold">
				<%: showTotal %> / 
				<%: expandTotal %> /
				<%: clickTotal %> / 
				<span class="red"><%: GetCTR(clickTotal, showTotal) %></span>
			</span></td>
		</tr>
	</tfoot>
</table>



<table class="bannerstbl" cellpadding=0 cellspacing=0>
	<thead><tr><td>Платформа</td><td>Показы / Клики</td><td>Доля в показах</td></tr></thead>
	<tbody>
		<tr>
		<%
			var totalPlatformShow = Model.PlatformRows.Sum(x => x.Shows);

			foreach (var row in Model.PlatformRows)
   {
%>
		<td><%: row.Platform.Name %></td>
		<td>
			<%: row.Shows %> / 
			<%: row.Clicks %>
		</td>
		<td><%: GetCTR(row.Shows, totalPlatformShow) %></td></tr>
		<%
   }%>
	</tbody>
</table>